package com.bishe.supermarket.service;

import com.bishe.supermarket.mapper.AdminMapper;
import com.bishe.supermarket.pojo.Admin;
import com.bishe.supermarket.pojo.vo.Status;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

@Service
public class PassWordService {
    @Autowired
    AdminMapper adminMapper;
    //修改密码
    public Status updatePassword(String oldPassword,String newPassword,String reNewPassword){
        Status status = new Status();

        String passWord = adminMapper.selectByName("admin");

        if(StringUtils.isBlank(newPassword)||StringUtils.isBlank(reNewPassword)){
            status.setCode(false);
            status.setMsg("密码不能为空！");
            return status;
        }

        if (!passWord.equals(oldPassword)){
          status.setCode(false);
          status.setMsg("旧密码输入有误！");
          return status;
        }

        if (!newPassword.equals(reNewPassword)){
            status.setMsg("确认密码有误！");
            status.setCode(false);
            return status;
        }
        Admin admin = new Admin();
        admin.setLoginName("admin");
        admin.setPassWord(newPassword);

        adminMapper.update(admin);

        status.setCode(true);
        status.setMsg("修改成功！");
        return status;


    }
}
